﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Pizzadetails.aspx.cs" Inherits="WebshopPizzaRio.Pizzadetails" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<div>
<h1>Pizzadetails</h1>
    
<br />
    <asp:Label ID="ErrorincorrectQueryString" runat="server" Text="Er is geen geldige pizzaid ingevuld. Of de pizza is niet publiekelijk." Visible = "false"></asp:Label>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PizzaRioConnectionString %>" 
        SelectCommand="select top 1 * from (
select pizza.naam AS 'Pizza', pizza.pizzaid,pizza.prijs AS 'Prijs', aanbiedingen.geldig from pizza INNER JOIN aanbiedingen ON pizza.pizzaid = aanbiedingen.pizzaid where aanbiedingen.geldig = 0 and pizza.pizzaid = @pizzaid AND pizza.publiekelijk = 1
UNION
select pizza.naam AS 'Pizza', pizza.pizzaid, aanbiedingen.aanbiedingprijs AS 'Prijs', aanbiedingen.geldig from aanbiedingen INNER JOIN pizza ON aanbiedingen.pizzaid = pizza.pizzaid where aanbiedingen.geldig = 1 and pizza.pizzaid = @pizzaid AND pizza.publiekelijk = 1
UNION
select pizza.naam AS 'Pizza', pizza.pizzaid, pizza.prijs AS 'Prijs', '' AS 'geldig' from pizza where pizza.publiekelijk = 1 and pizza.pizzaid = @pizzaid)
AS x">
        <SelectParameters>
            <asp:QueryStringParameter Name="pizzaid" QueryStringField="id" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PizzaRioConnectionString %>" 
        SelectCommand="SELECT ingredienten.naam AS 'Ingredienten' FROM pizzaregel
	INNER JOIN ingredienten
	ON pizzaregel.ingredientnr = ingredienten.ingredientnr
	INNER JOIN pizza
	ON pizzaregel.pizzaid = pizza.pizzaid
WHERE pizzaregel.pizzaid = @pizzaid">
        <SelectParameters>
            <asp:QueryStringParameter Name="pizzaid" QueryStringField="id" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PizzaRioConnectionString %>" 
        SelectCommand="select top 1 x.Pizza AS 'Pizza', x.userid AS 'userid', x.pizzaid AS 'pizzaid', x.Prijs AS 'Prijs', x.geldig AS 'geldig' from (
select pizza.naam AS 'Pizza',pizza.userid, pizza.pizzaid, aanbiedingen.aanbiedingprijs AS 'Prijs', aanbiedingen.geldig from aanbiedingen INNER JOIN pizza ON aanbiedingen.pizzaid = pizza.pizzaid where aanbiedingen.geldig = 1 and pizza.pizzaid = @pizzaid AND pizza.publiekelijk = 1 AND pizza.userid = @userid
UNION
select pizza.naam AS 'Pizza',pizza.userid, pizza.pizzaid,pizza.prijs AS 'Prijs', aanbiedingen.geldig from pizza INNER JOIN aanbiedingen ON pizza.pizzaid = aanbiedingen.pizzaid where aanbiedingen.geldig = 0 and pizza.pizzaid = @pizzaid AND pizza.publiekelijk = 1 AND pizza.userid =@userid
UNION

select pizza.naam AS 'Pizza',pizza.userid, pizza.pizzaid, aanbiedingen.aanbiedingprijs AS 'Prijs', aanbiedingen.geldig from aanbiedingen INNER JOIN pizza ON aanbiedingen.pizzaid = pizza.pizzaid where aanbiedingen.geldig = 1 and pizza.pizzaid = @pizzaid AND pizza.publiekelijk = 1
UNION
select pizza.naam AS 'Pizza',pizza.userid, pizza.pizzaid,pizza.prijs AS 'Prijs', aanbiedingen.geldig from pizza INNER JOIN aanbiedingen ON pizza.pizzaid = aanbiedingen.pizzaid where aanbiedingen.geldig = 0 and pizza.pizzaid = @pizzaid AND pizza.publiekelijk = 1
UNION

select pizza.naam AS 'Pizza',pizza.userid, pizza.pizzaid, pizza.prijs AS 'Prijs', '' AS 'geldig' from pizza where pizza.pizzaid = @pizzaid AND pizza.userid = @userid AND pizza.publiekelijk = 0
UNION
select pizza.naam AS 'Pizza',pizza.userid, pizza.pizzaid, pizza.prijs AS 'Prijs', '' AS 'geldig' from pizza where pizza.pizzaid = @pizzaid AND pizza.publiekelijk = 1
)
AS x" onselected="SqlDataSource3_Selected">
        <SelectParameters>
            <asp:QueryStringParameter Name="pizzaid" QueryStringField="id" Type="Int32" />
            <asp:SessionParameter Name="userid" SessionField="SessionUserId" Type="Object" />
        </SelectParameters>
    </asp:SqlDataSource>






    <asp:ListView ID="ListView1" runat="server"
        DataKeyNames = "pizzaid, Pizza, Prijs" 
        onselectedindexchanging="ListView1_SelectedIndexChanging">

        <LayoutTemplate>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
        </LayoutTemplate>
        <ItemTemplate>
            <div class="leftpizzadetails"><img src = "Images/Pizzadetails/<%#Eval("pizzaid") %>.jpeg" alt = "Van deze pizza is geen foto beschikbaar" /></div>
            <div class="rightpizzadetails">

                Pizza: <%#Eval("Pizza") %>
                <br />
                Prijs: €<%#Eval("Prijs") %>
                <br />
                <asp:LinkButton ID="SelectPizza" runat="server" CommandName = "Select">Voeg toe aan de winkelwagen</asp:LinkButton>
                </div>
        </ItemTemplate>
    </asp:ListView>

    <br />
    <div class="rightpizzadetails">
            <asp:Label ID="Label1" runat="server" Text="Ingredienten:"></asp:Label>
    </div>
    <br />

    <div class="rightpizzadetails">
    <asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2">

        <LayoutTemplate>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
        </LayoutTemplate>
        
        <ItemTemplate>
        
            <ul>
            <li><%#Eval("Ingredienten") %></li>
            </ul>
        
        </ItemTemplate>
    </asp:ListView>
    </div>
</div>

</asp:Content>
